

# package org.apache.jena.datatypes.xsd;

# import java.util.Arrays;

# import org.apache.jena.graph.impl.LiteralLabel;

'''
 * Root class for XSD datatypes with binary values, xsd:hexBinary and xsd:base64Binary.
 * The binary value is stored as a byte[] in the LiteralLabel.
'''
# abstract
from base.datatypes.xsd.XSDDatatype import XSDDatatype
from base.java.Arrays import Arrays

class XSDbinary(XSDDatatype):
    '''
     * @param typeName the name of the XSD type to be instantiated, this is
     * used to lookup a type definition from the Xerces schema factory.
    '''
    # param String boolean
    def __init__(self, typename, register):
        super().__init__(typename)

    #protected XSDbinary(String typeName, boolean register):
    #    super(typeName, register ? byte[].class : null);
    

    '''
     * Test whether the given object is a legal value form
     * of this datatype. Brute force implementation.
    '''
    # @Override
    # param Object
    # return boolean
    def isValidValue(self, valueForm):
        # (valueForm instanceof byte[])
        return isinstance(valueForm, list)
    

    '''
     * Compares two instances of values of the given datatype.
    '''
    # @Override
    # param LiteralLabel LiteralLabel
    # return boolean
    def isEqual(self, value1, value2):
        return value1.getDatatype() == value2.getDatatype() and value1.getValue() == value2.getValue()
                # && Arrays.equals((byte[]) value1.getValue(), (byte[]) value2.getValue());
    

    # @Override
    # param LiteralLabel
    # return int
    def getHashCode(self, lit):
        if (lit.isWellFormed()):
            return Arrays.hashCode(lit.getValue())
        else:
            return lit.getLexicalForm().hashCode()
    


